{include file="public/nheader"}
<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div class="layui-card-header layadmin-card-header-auto ">
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input name="title" class="layui-input" type="text" placeholder="昵称|绑定手机账号" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input name="mobile" class="layui-input" type="text" placeholder="服务姓名|服务手机号" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="type" lay-verify="">
                                <option value="">用户类型</option>
                                <option value="1" {if !empty(input('get.type')) && input('get.type')==1}selected{/if}>
                                </option>
                                微信用户</option>
                                <option value="2" {if !empty(input('get.type')) && input('get.type')==2}selected{/if}>
                                    抖音用户</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <!-- // 默认搜索 -->
                        <button class="layui-btn icon-btn" lay-filter="formSearch" lay-submit>搜索</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- // 创建数据实例 -->
        <table id="lay-tableList" lay-filter="lay-tableList"></table>
    </div>
</div>

<script type="text/html" id="datagrid-toolbar">
</script>

<!-- // 列表工具栏 -->
<script type="text/html" id="tableBar">
    <!-- <a class="layui-table-text" lay-open data-title="赠送优惠券" data-area="80%,90%" data-url="/user/sendcoupon?user_id={{d.id}}" >赠送优惠券</a>
    <div class="layui-divider layui-divider-vertical"></div> -->
<a class="layui-table-text" lay-open data-title="管理优惠券" data-area="80%,90%"
    data-url="/user/coupon?user_id={{d.id}}">管理优惠券</a>

</script>
<script type="text/html" id="moneyBar">
    <a style="color:blue" class="layui-table-text" lay-open data-title="明细" data-area="60%,80%" data-url="/user/moneylog?id={{d.id}}" >{{d.money}}</a>
    <a class="layui-table-text" data-title="操作资产" data-area="30%,40%" callback="edits" data-url="#adminforms" lay-event="edit">修改资产</a>
</script>
<script type="text/html" id="adminforms">
    <div class="layui-fluid layui-bg-white">
        <form class="layui-form layui-form-fixed" lay-filter="adminforms">
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red">* </font>用户ID:</label>
                    <div class="layui-input-block">
                        <input name="id" style="border:none;display: inline-block;" class="layui-input" disabled onlyread/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><font color="red">* </font>用户昵称:</label>
                        <div class="layui-input-block">
                            <input name="nickName" style="border:none;display: inline-block;" class="layui-input" disabled onlyread/>
                        </div>
                    </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red">* </font>可用金额:</label>
                    <div class="layui-input-block">
                        <input name="money" style="border:none;display: inline-block;" class="layui-input" disabled onlyread/>
                    </div>
                </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red">* </font>类型:</label>
                <div class="layui-input-block">
                    <input type="radio" name="type" value="1" title="充值" checked>
                    <input type="radio" name="type" value="2" title="消费">
                </div>
            </div>
            <div class="layui-form-item">
            <label class="layui-form-label"><font color="red">* </font>变更金额:</label>
                <div class="layui-input-block">
                    <input name="moneys" value=""  placeholder="增减金额" type="number" class="layui-input" lay-verify="required" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red">* </font>操作说明:</label>
                <div class="layui-input-block">
                    <textarea name="desc" placeholder="请输入内容" class="layui-textarea" lay-verify="required" >平台扣除</textarea>
                </div>
            </div>
        <div class="layui-footer layui-form-item layui-center ">
            <button class="layui-btn" lay-filter="submitPage" lay-submit>提交</button>
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closePageDialog" >取消</button>
        </div>
        </form>
    </div>
</script>
{include file="public/nfooter"}
<script>
    layui.use(['admin', 'layer', 'table', 'form'], function () {
        var admin = layui.admin;
        var layer = layui.layer;
        var table = layui.table;        // 表格
        var form = layui.form;
        /*
         * 初始化表格
        */
        admin.callback.edits = function (clickthis, colletction, config) {
            var tableThis = colletction.tableThis;
            // 监听权限提交
            form.on("submit(submitPage)", function (post) {
                // 获取用户id
                var pageThat = layui.$(this);
                pageThat.attr("disabled", true);
                // 开始POST提交数据
                post.field.id = tableThis.data.id;
                var index = layer.load(1); //换了种风格           
                layui.$.post("{:url('user/money_edit')}", post.field, function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg);
                        // 关闭当前窗口
                        table.reload('lay-tableList');
                        layer.close(colletction.index);
                        layer.close(index);
                        pageThat.attr("disabled", false);
                    }
                    else {
                        layer.error(res.msg);
                        layer.close(index);
                        pageThat.attr("disabled", false);
                    }
                }, 'json');
                return false;
            })
        }
        var isTable = table.render({
            elem: "#lay-tableList"
            , url: "{:url()}"
            , page: true
            , size: 'lg'
            , even: true
            , where: {
                id: "{:input('id/d',0)}"
            }
            , cols: [[
                { type: 'checkbox', width: 60 },
                { field: 'id', align: 'center', sort: true, width: 80, title: 'ID' },
                { field: 'nickName', width: 250, align: 'center', title: '昵称' },
                {
                    field: 'type', align: 'center', width: 100, templet: function (d) {
                        if (d.type == 1) {
                            return '微信用户';
                        }
                        if (d.type == 2) {
                            return '抖音用户';
                        }
                        return '未知';
                    }, title: '性别'
                },
                {
                    field: 'sex', align: 'center', width: 100, templet: function (d) {
                        if (d.sex == 1) {
                            return '男';
                        }
                        if (d.sex == 2) {
                            return '女';
                        }
                        return '未知';
                    }, title: '性别'
                },
                {
                    field: 'money', align: 'center', width: 200, toolbar: '#moneyBar', title: '余额明细'
                },
                {
                    field: 'money', align: 'center', width: 200, templet: function (d) {
                        return '<a style="color:blue" class="layui-table-text" lay-open data-title="积分明细" data-area="60%,80%" data-url="/user/interlog?id=' + d.id + '" >' + d.integral + '(累计:' + d.integralall + ')</a>';
                    }, title: '积分明细'
                },

                {
                    field: 'address', width: 200, align: 'center', templet: function (d) {
                        if (d.address == false) {
                            return '无';
                        }
                        return d.address.province_name + d.address.city_name + d.address.area_name + d.address.street_name;
                    }, title: '地址信息'
                },
                {
                    field: 'address', width: 200, align: 'center', templet: function (d) {
                        if (d.address == false) {
                            return '无';
                        }
                        return d.address.name + d.address.mobile;
                    }, title: '联系信息'
                },
                {
                    field: 'avatarUrl', align: 'center', width: 80, templet: function (d) {
                        return d.avatarUrl ? '<div><img src="' + d.avatarUrl + '"height="32" lay-image-click="" lay-size="100,100" ></div>' : '<div></div>';
                    }, title: '头像'
                },
                {
                    field: 'mobile', width: 200, align: 'center', title: '手机账号', templet: function (d) {
                        if (d.mobile == null || d.mobile == '' || d.mobile == 'undefined') {
                            return '未授权';
                        }
                        return d.mobile;
                    }
                },
                { field: 'level_name', width: 200, align: 'center', title: '会员级别' },
                { field: 'user_name', width: 250, align: 'center', title: '推荐人昵称' },
                { field: 'created', width: 200, align: 'center', title: '创建时间' },
                { align: 'center', toolbar: '#tableBar', width: 250, title: '操作' },
            ]]
        })
    })
</script>